home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / argh11.zip / ARGH.BAS
BASIC Source File  |  1986-08-22  |  8KB  |  132 lines

  1. 1 REM VERSION 1.1 FIXED ALOT OF BUGS
  2. 10 rem   Here are some limitations of IBM's Basic Compiler 2.0 and
  3. 20 rem rather detailed instructions of how to program around them.
  4. 30 rem When compiling programs larger in source than the 64 kilobyte
  5. 40 rem limit inherent in the compiler, you may either run out of
  6. 50 rem compiler space giving the ^TC (too compilcated error) of the
  7. 60 rem linker may give the obstruce error "Data out of segment bounds"
  8. 70 rem (meaning the object code created has data or program code
  9. 80 rem larger than 64K, it is known that object code can be generated
  10. 90 rem beyond 128K and still link successfully).
  11. 100 rem   On may ask, "Is this really relevant to anything I* would
  12. 110 rem ever do?" and stop reading. This is certainly not a problem
  13. 120 rem you would run into everyday, however, for us hackers out here
  14. 130 rem in bbs-land, we have been fighting with this problem for what
  15. 140 rem seems like a long time! RBBS has this certain limitation, I
  16. 150 rem am sure. Even my own bbs is definitely running full steam
  17. 160 rem into it day in and day out. Here are some tips.
  18. 170 rem   Why compile with the /E switch in the first place? If you
  19. 180 rem write code with no error, why trap any? Take this program:
  20. 190 rem 10 ON ERROR GOTO 20
  21. 200 rem 15 PRINT "AN ERROR HERE? NEVER!":END
  22. 210 rem 20 PRINT "OOPS!"
  23. 220 rem 30 RESUME 15
  24. 230 rem 40 STOP
  25. 240 rem Seriously, the /E switch generates two bytes of extra code for
  26. 250 rem each line in your program. This gets a bit more complex as I
  27. 260 rem will try to point out. IBM's Basic Compiler 2.0 has the ability
  28. 270 rem to link separately compiled 'subprograms' together. Each of
  29. 280 rem may itself be up to 64K of code (up to 64K for all subprograms
  30. 290 rem is used for data space, so beware!) Thus, you could compile
  31. 300 rem ten programs and link each object module into one giant
  32. 310 rem executable file. Read your manual for further details. Also
  33. 320 rem see the COMMAND SHARED statement. But, what does this have to
  34. 330 rem do with the /E switch? Simply put, these neat little subprograms
  35. 340 rem do not allow error trapping... (no ON ERROR statements!)
  36. 350 rem   To overcome large module constraints in the second release
  37. 360 rem of IBM's Basic Compiler while programming communications (yes,
  38. 370 rem this is what I was getting at the whole time) we found a way
  39. 380 rem to do without the OPEN "COM... statement altogether since it
  40. 390 rem requires error trapping for it's various related methods of
  41. 400 rem receiving data from the device into your program (INPUT$ when
  42. 410 rem someone hangs up, for example) and since you cannot CHAIN another
  43. 420 rem compiled Basic program and re-open the communications port without
  44. 430 rem either dropping the carrier or receiving an error message to the
  45. 440 rem effect that it is already open (or try writing to it when it
  46. 450 rem isn't open. ARGH!)
  47. 460 rem   On method is to access the serial ports directly for input,
  48. 470 rem output, and detecting carrier or the status of other parts of
  49. 480 rem the modem itself. Basically (hah) we start by turning on the
  50. 490 rem DTR lead (see your modem manual for whatever correct switches must
  51. 500 rem be set) with the statement OUT 1020,1 next send the ATZ code
  52. 510 rem (let's assume you have a hayes compatible) through a routine
  53. 520 rem which is listed below. After that, some other modem commands
  54. 530 rem may be necessary, in particular, ATE0Q1 or ATS2=255S0=1 (see
  55. 540 rem your manual for the exact meaning of these) Then wait for the
  56. 550 rem modem to ring and send the ATA command. The modem status
  57. 560 rem register's seventh bit, the ring indicator bit, can be examined.
  58. 570 rem This short peice of code works:
  59. 580 rem WHILE(INP(1022)AND 64)=0:WEND:A$="ATA":GOSUB 1000
  60. 590 rem The last step is to wait for a carrier, the following code works:
  61. 600 rem WHILE(INP(1022)<128:WEND It is a good idea to time how long
  62. 610 rem each loop is being thrashed through and to disconnect before
  63. 620 rem thirty seconds has elapsed (then hang up the modem with
  64. 630 rem OUT 1020,0 -- this can also be done at any time while your
  65. 640 rem program is running and the carrier is present)
  66. 650 rem   Now that you have a carrier and the program is interacting
  67. 660 rem with a user, take a look at the example program below, with it's
  68. 670 rem sparse remarks and notice the modem input and output routines,
  69. 680 rem in fact the whole program, is working without ever opening
  70. 690 rem the communications port.
  71. 700 rem   This document was typed in by an anonymous hacker. The
  72. 710 rem program was written by a large team of programmers on their
  73. 720 rem lunch break.
  74. 721 rem *** Begin program ***
  75. 722 rem
  76. 723 DEF FNTI!=VAL(MID$(TIME$,1,2))*3600+VAL(MID$(TIME$,4,2))*60+VAL(MID$(TIME$,7,2))
  77. 725 rem Turn on the DTR lead
  78. 730 OUT 1020,1
  79. 731 rem Initialize the modem and wait two seconds for the OK response
  80. 733 A$="ATZ":GOSUB 8740:SOUND 32767,36
  81. 734 rem Instruct the modem to answer the phone after one ring
  82. 736 A$="ATQ1ES2=255S0=1":GOSUB 8740
  83. 737 rem Wait for the phone to ring
  84. 738 WHILE(INP(1022)AND 64)=0:WEND
  85. 739 rem Modem answers phone. Wait for carrier or timeout
  86. 741 T2!=FNTI!:WHILE(INP(1022)<128):GOSUB 8730:WEND:QQ=1:OUT 1019,3
  87. 742 rem Initialize the baud variables
  88. 743 rem ** Find out if it's 300,1200 and No parity or Even parity
  89. 744 '      Look at the buffer until a character is entered
  90. 745          WHILE(INP(1021)AND 1)=0:WEND
  91. 750          A=0:WHILE A=0:A=INP(1016):WEND:SWAP Q,QQ
  92. 751 '      If it is ascii 13 then it found even parity
  93. 752          IF A=13 THEN 200
  94. 753 '      If it is ascii 141 then it is a return with an extra bit,
  95. 754 '      then set the register to reflect this
  96. 755          IF A=141 THEN OUT 1019,26:GOTO 200
  97. 758 '      Store the line status register value
  98. 759          R1=INP(1019)
  99. 760 '      Set the divisor latch so the I/O buffer becomes the baud generator
  100. 761          OUT 1019,R1 OR 128:IF Q THEN OUT 1016,128:OUT 1017,1 ELSE OUT 1016,96:OUT 1017,0
  101. 762 '      Recode the baud. The baud is alternated until CR is found.
  102. 763          IF Q THEN OUT 1016,128:OUT 1017,1 ELSE OUT 1016,96:OUT 1017,0
  103. 764 '      Restore the I/O buffer by resetting the divisor latch
  104. 770          OUT 1019,R1:OUT 1019,3:GOSUB 8730:GOSUB 8730:GOTO 750
  105. 771 '      Set parity to none, check for carrier loss, and timeout
  106. 772          OUT 1019,3:GOSUB 8730:GOSUB 8730:GOTO 745
  107. 780 rem ** At this stage it has found the correct baud and parity..
  108. 790 A$="Welcome to beta site X":GOSUB 1010
  109. 800 A$="Enter your name:":GOSUB 2001:STOP
  110. 810 rem add your program here
  111. 1000 rem ***** modem output routine *****
  112. 1010 FOR A=1 TO LEN(A$)
  113. 1011 IF(INP(1021)AND 1) THEN D$=CHR$(INP(1016))
  114. 1030 B$=MID$(A$,A,1):PRINT B$;
  115. 1040 IF INP((1021)AND 32)=0 THEN 1040
  116. 1050 GOSUB 8730:OUT 1016,ASC(B$):NEXT:RETURN
  117. 2000 rem ***** modem input routine *****
  118. 2001 WHILE(INP(1021)AND 1)=0:WEND
  119. 2002 GOSUB 8730:C$=CHR$(INP(1016))
  120. 2003 IF C$=CHR$(8) AND LEN(A$) THEN A$=LEFT$(A$,LEN(A$)-1):PRINT CHR$(29);CHR$(32);CHR$(29);:C$=CHR$(8)+CHR$(32)+CHR$(8):GOSUB 8760
  121. 2004 PRINT C$;:GOSUB 8760:IF Y$=CHR$(13)THEN RETURN
  122. 2005 A$=A$+C$:GOTO 2001
  123. 3000 REM ***** check carrier *****
  124. 8730 IF INP(1022)<128 THEN END ELSE RETURN
  125. 8735 rem ***** send a modem command *****
  126. 8740 A$=A$+CHR$(13):FOR A=1 TO LEN(A$):IF(INP(1021)AND 1)THEN DUMY=INP(1016)
  127. 8745 GOSUB 8770:OUT 1016,ASC(MID$(A$,A,1)):NEXT:RETURN
  128. 8750 rem ***** send a character to the modem *****
  129. 8760 GOSUB 8770:GOSUB 8730:OUT 1016,ASC(C$):RETURN
  130. 8770 IF(INP(1021)AND 32)=0 THEN 8770 ELSE RETURN
  131.  
  132.